package cn.virens.web.components.open.wxma.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.virens.web.components.open.wxma.WxMaServiceImpl;

/**
 * 微信配置默认实例化对象
 * 
 * @author virens
 */
@Component
public class WxMaCacheConfigImpl extends WxMaCacheConfigByJCache {
	private @Autowired WxMaServiceImpl mWxMaService;

	@Value("${weixin.cfg.ma.appid}")
	private String weixinConfigAppid;

	@Value("${weixin.cfg.ma.token}")
	private String weixinConfigToken;

	@Value("${weixin.cfg.ma.secret}")
	private String weixinConfigSecret;

	@Value("${weixin.cfg.ma.aeskey}")
	private String weixinConfigAeskey;

	@Value("${weixin.cfg.ma.format}")
	private String weixinConfigFormat;

	@Override
	public String getAppid() {
		return weixinConfigAppid;
	}

	@Override
	public String getToken() {
		return weixinConfigToken;
	}

	@Override
	public String getSecret() {
		return weixinConfigSecret;
	}

	@Override
	public String getAesKey() {
		return weixinConfigAeskey;
	}

	@Override
	public String getMsgDataFormat() {
		return weixinConfigFormat;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		super.afterPropertiesSet();

		// 将当前配置设置为微信服务的默认配置
		this.mWxMaService.addConfigStorage(this);
		this.mWxMaService.switchover(getAppid());
		this.mWxMaService.initHttp();
	}
}
